% Column definition in B_Data
clear b
b.firmid = 1; b.date = 2; b.BRisk = 3; b.PRisk = 4; b.IV_Ave = 5; b.call = 6; b.put = 7;
date = unique(B_Data(:,b.date));

% Difference in PRisk
for i = 1:size(date,1)
    B = B_Data(find(B_Data(:,b.date)==date(i)),:);
    Figure_PRisk(i,1) = nanmean(B(find(B(:,b.BRisk)==1),b.PRisk));
    Figure_PRisk(i,2) = nanmean(B(find(B(:,b.BRisk)==0),b.PRisk));
end
Figure_PRisk(:,3) = Figure_PRisk(:,1) - Figure_PRisk(:,2);
clear i B 

figure(2); subplot(2,2,1)
plot(Figure_PRisk(:,3)); 
title('Difference in PRisk between treated and control')

% IV
for i = 1:size(date,1)
    B = B_Data(find(B_Data(:,b.date)==date(i)),:);
    Figure_IV(i,1) = nanmean(B(find(B(:,b.BRisk)==1),b.IV_Ave));
    Figure_IV(i,2) = nanmean(B(find(B(:,b.BRisk)==0),b.IV_Ave));
end
Figure_IV(:,3) = Figure_IV(:,1) - Figure_IV(:,2); 
clear i B 
figure(2); subplot(2,2,2) 
plot(Figure_IV(:,3)); 
title('Difference in IV between treated and control')

% Call
for i = 1:size(date,1)
    B = B_Data(find(B_Data(:,b.date)==date(i)),:);
    Figure_Call(i,1) = nanmean(B(find(B(:,b.BRisk)==1),b.call));
    Figure_Call(i,2) = nanmean(B(find(B(:,b.BRisk)==0),b.call));
end
Figure_Call(:,3) = Figure_Call(:,1) - Figure_Call(:,2);
Figure_Call(1:12,4) = mean(Figure_Call(1:12,1));
Figure_Call(1:12,5) = mean(Figure_Call(1:12,2));
Figure_Call(14:25,4) = mean(Figure_Call(14:25,1));
Figure_Call(14:25,5) = mean(Figure_Call(14:25,2));
Figure_Call(13,:)=nan;
clear i B
figure(2); subplot(2,2,3)
plot(Figure_Call(:,[1 2 4 5])); 
title('Call returns between treated and control')

% Put
for i = 1:size(date,1)
    B = B_Data(find(B_Data(:,b.date)==date(i)),:);
    Figure_Put(i,1) = nanmean(B(find(B(:,b.BRisk)==1),b.put));
    Figure_Put(i,2) = nanmean(B(find(B(:,b.BRisk)==0),b.put));
end
Figure_Put(:,3) = Figure_Put(:,1) - Figure_Put(:,2);
Figure_Put(1:12,4) = mean(Figure_Put(1:12,1));
Figure_Put(1:12,5) = mean(Figure_Put(1:12,2));
Figure_Put(14:25,4) = mean(Figure_Put(14:25,1));
Figure_Put(14:25,5) = mean(Figure_Put(14:25,2));
Figure_Put(13,:)=nan;
clear i B
figure(2); subplot(2,2,4)
plot(Figure_Put(:,[1 2 4 5])); 
title('Put returns between treated and control')